import Vue from 'vue'
import Router from 'vue-router'
import PageTransition from '@/components/PageTransition' //默认
Vue.use(Router);
function fn__ (obj) {
  let lang = localStorage.getItem("lang") || 'ch'; // 语言标识
  return obj[lang];
}
// 渠道、设备
export default new Router({
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop;
      }
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  },
  routes: [{
    path: '/',
    component: PageTransition,
    children: [
      {
        path: '/',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/index')), 'index'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/index')), 'index')
        })

      },
      {
        path: '/front/',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/index')), 'index'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/index')), 'index')
        })

      },
      {
        path: '/front/search',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/search')), 'search'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/search')), 'search')
        })

      },
      {
        path: '/front/commons',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/commons')), 'commons'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/commons')), 'commons')
        })

      },
      {
        path: '/front/index',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/index')), 'index'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/index')), 'index')
        })

      },
      {
        path: '/front/sitemap',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/sitemap')), 'sitemap'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/sitemap')), 'sitemap')
        })

      },
      {
        path: '/front/article',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/article')), 'article'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/article')), 'article')
        })

      },
      {
        path: '*',
        component: fn__({
          'ch': resolve => require.ensure([], () => resolve(require('@/vue/ch/404')), '404'),
          'en': resolve => require.ensure([], () => resolve(require('@/vue/en/404')), '404')
        })
      },
    ]
  }]
})